<?php

namespace App\Observers;

use App\Models\SpecificationAttribute;
use App\Services\SpecificationService;

class SpecificationAttributeObserver
{
    protected $specificationService;

    public function __construct(SpecificationService $specificationService)
    {
        $this->specificationService = $specificationService;
    }

    /**
     * Handle the SpecificationAttribute "created" event.
     */
    public function created(SpecificationAttribute $specificationAttribute): void
    {
        $this->clearCache();
    }

    /**
     * Handle the SpecificationAttribute "updated" event.
     */
    public function updated(SpecificationAttribute $specificationAttribute): void
    {
        $this->clearCache();
    }

    /**
     * Handle the SpecificationAttribute "deleted" event.
     */
    public function deleted(SpecificationAttribute $specificationAttribute): void
    {
        $this->clearCache();
    }

    /**
     * Handle the SpecificationAttribute "restored" event.
     */
    public function restored(SpecificationAttribute $specificationAttribute): void
    {
        $this->clearCache();
    }

    /**
     * Handle the SpecificationAttribute "force deleted" event.
     */
    public function forceDeleted(SpecificationAttribute $specificationAttribute): void
    {
        $this->clearCache();
    }

    /**
     * 清除规格属性缓存
     */
    private function clearCache(): void
    {
        $this->specificationService->clearCache();
    }
}